package com.csh.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csh.order.entity.TbGoods;
import com.csh.order.service.TbGoodsService;
import com.csh.order.mapper.TbGoodsMapper;
import com.csh.utils.ResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 86176
* @description 针对表【tb_goods】的数据库操作Service实现
* @createDate 2022-08-26 08:38:32
*/
@Service
public class TbGoodsServiceImpl extends ServiceImpl<TbGoodsMapper, TbGoods>
    implements TbGoodsService{
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    TbGoodsMapper tbGoodsMapper;
    @Override
    public ResultResponse findGoodsPage() {
        Object redisGoodsList = redisTemplate.opsForHash().get("redisGoodsList", "redisGoodsList");
        List<TbGoods> goods=new ArrayList<>();
        if(redisGoodsList!=null && redisGoodsList instanceof List){
            goods= (List<TbGoods>) redisGoodsList;
        }else{
             goods = tbGoodsMapper.selectList(null);
            redisTemplate.opsForHash().put("redisGoodsList", "redisGoodsList",goods);
        }

        return ResultResponse.SUCCESS(goods);
    }
}




